package com.briup.mt.web.controller;

import com.briup.mt.service.IGreenhouseService;
import com.briup.mt.bean.Greenhouse;
import com.briup.mt.utils.Message;
import com.briup.mt.utils.MessageUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/greenhouse")
@Validated
public class Greenhousecontroller {
    @Resource
    private IGreenhouseService greenhouseService;

    @GetMapping("query")
    public Message query(String name) {
        List<Greenhouse> list = greenhouseService.query(name);
        return MessageUtil.success(list);
    }

    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Greenhouse file) {
        greenhouseService.saveOrUpdate(file);
        return MessageUtil.success("操作成功");
    }

    @DeleteMapping("deleteById")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="温室气体",required = true,paramType = "query")
    })
    public Message deleteById(@NotNull Long id) {
        greenhouseService.deleteById(id);
        return MessageUtil.success("删除成功");
    }
}
